﻿using UnityEngine;

public class EnemyViewCreator : Singleton<EnemyViewCreator>
{
    private string path = "Prefabs/EnemyView/";

    public EnemyView CreateEnemyView(Enemy enemyData, GameObject viewSlot)
    {
        // 根据传入的 enemyData 类型，得到类名
        string className = enemyData.Name;
        string fullPath = path + className;

        EnemyView prefab = Resources.Load<EnemyView>(fullPath);
        //Debug.Log($"Trying to load prefab at: {fullPath}");
        if (prefab == null)
        {
            //Debug.LogError($"Prefab not found at path: Resources/{fullPath}");
            return null;
        }

        // 实例化预制体并挂到 viewSlot 下
        EnemyView enemyView = Instantiate(prefab, viewSlot.transform);

        // 调用 Setup，传入 enemyData
        enemyView.Setup(enemyData);
        return enemyView;
    }
    public EnemyView CreateEnemyView(Enemy enemyData, Transform viewSlot)
    {
        // 根据传入的 enemyData 类型，得到类名
        string className = enemyData.Name;
        string fullPath = path + className;

        EnemyView prefab = Resources.Load<EnemyView>(fullPath);
        //Debug.Log($"Trying to load prefab at: {fullPath}");
        if (prefab == null)
        {
            //Debug.LogError($"Prefab not found at path: Resources/{fullPath}");
            return null;
        }

        // 实例化预制体并挂到 viewSlot 下
        EnemyView enemyView = Instantiate(prefab, viewSlot.transform);

        // 调用 Setup，传入 enemyData
        enemyView.Setup(enemyData);
        return enemyView;
    }
}
